<template>
  <div class="body">
    <div class="body-top">
      <div class="body-top-title">
        <el-select v-model="station" placeholder="请选择" :popper-append-to-body="false" @change="changeStation">
          <span slot="prefix">站点:</span>
          <el-option v-for="item in stations" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </div>
    </div>
    <div class="body-content">
      <div class="body-content-top">
        <div class="body-content-top-left"><span>任务日历</span></div>
        <div class="body-content-top-right"><span>查询选项</span></div>
      </div>
      <div class="body-content-bottom">
        <div class="body-content-bottom-left">
          <el-calendar ref="calendar" v-model="taskCalendar">
            <template slot="dateCell" slot-scope="{date, data}">
              <p :class="data.isSelected ? 'text-selected' : 'text-default'">
                {{ data.day.split('-')[2] }}
              </p>
              <div v-if="taskStateList && taskStateList[formattedDate(date)]">
                <div :class="data.isSelected ? 'task-status-selected' : 'task-status'"><span>等待执行</span><span
                    class="task-count" style="color: rgba(255, 255, 255, 1);">
                    {{ taskStateList[formattedDate(date)].webTaskStateCountVOList.filter(item => item.taskState ==
          '0')[0].stateCount }}</span></div>
                <div :class="data.isSelected ? 'task-status-selected' : 'task-status'"><span>已完成</span><span
                    class="task-count" style="color: rgba(54, 224, 45, 1);">
                    {{ taskStateList[formattedDate(date)].webTaskStateCountVOList.filter(item => item.taskState ==
          '1')[0].stateCount }}</span></div>
                <div :class="data.isSelected ? 'task-status-selected' : 'task-status'"><span>未执行</span><span
                    class="task-count" style="color: rgba(224, 194, 45, 1);">
                    {{ taskStateList[formattedDate(date)].webTaskStateCountVOList.filter(item => item.taskState ==
          '2')[0].stateCount }}</span></div>
                <div :class="data.isSelected ? 'task-status-selected' : 'task-status'"><span>任务超期</span><span
                    class="task-count" style="color: rgba(224, 57, 45, 1);">
                    {{ taskStateList[formattedDate(date)].webTaskStateCountVOList.filter(item => item.taskState ==
          '3')[0].stateCount }}</span></div>
                <div :class="data.isSelected ? 'task-status-selected' : 'task-status'"><span>挂牌未执行</span><span
                    class="task-count" style="color: rgba(224, 194, 45, 1);">
                    {{ taskStateList[formattedDate(date)].webTaskStateCountVOList.filter(item => item.taskState ==
          '4')[0].stateCount }}</span></div>
                <div :class="data.isSelected ? 'task-status-selected' : 'task-status'"><span>正在执行</span><span
                    class="task-count" style="color: rgba(5, 250, 240, 1);">
                    {{ taskStateList[formattedDate(date)].webTaskStateCountVOList.filter(item => item.taskState ==
          '5')[0].stateCount }}</span></div>
              </div>
            </template>
          </el-calendar>
        </div>
        <div class="body-content-bottom-right">
          <div class="body-content-bottom-right-search">
            <div class="search-input">
              <div class="custom-input">
                <span>开始时间：</span>
                <el-date-picker v-model="startTime" type="datetime" placeholder="请选择开始时间" />
              </div>
              <div class="custom-input">
                <span>结束时间：</span>
                <el-date-picker v-model="endTime" type="datetime" placeholder="请选择结束时间" />
              </div>
              <div class="custom-input">
                <el-input v-model="taskName" placeholder="请输入">
                  <template slot="prepend">任务名称：</template>
                </el-input>
              </div>
            </div>
            <div class="search-checkbox">
              <span>任务状态：</span>
              <el-checkbox-group v-model="checkedStatus">
                <el-checkbox v-for="status in taskStatus" :key="status.taskState" :label="status.taskState">{{
          status.taskStateName }}</el-checkbox>
              </el-checkbox-group>
            </div>
            <div class="search-checkbox">
              <span>巡视类型：</span>
              <el-checkbox-group v-model="checkedType">
                <el-checkbox v-for="patroltype in patrolTypes" :key="patroltype.patrolType"
                  :label="patroltype.patrolType">{{
                  patroltype.patrolTypeName }}</el-checkbox>
              </el-checkbox-group>
            </div>
            <div class="search-btn">
              <el-button @click="search">查询</el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </div>
          <div class="body-content-bottom-right-taskListTitle">
            <span>查询列表</span>
          </div>
          <div class="body-content-bottom-right-table">
            <div class="body-content-bottom-right-taskList">
              <div class="taskList-table">
                <el-table :data="taskData" style="width: 100%;">
                  <el-table-column type="index" label="序号" width="80" />
                  <el-table-column prop="taskName" label="任务名称" width="180" />
                  <el-table-column prop="planStartTime" label="计划开始时间" width="240" />
                  <el-table-column prop="taskStateName" label="任务状态" width="180" />
                  <el-table-column prop="patrolTypeName" label="巡视类型" width="200" />
                  <el-table-column label="操作" class="end-column">
                    <!-- <template slot-scope="scope">
                      <el-button type="text" size="small" @click="handleQuery(scope.row)"><span style="color: rgba(0, 255, 255, 1);">查看</span></el-button>
                    </template> -->
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
          <div class="body-content-bottom-right-page">
            <el-pagination background layout="total, prev, pager, next" :page-size="pageSize" :total="total"
              :current-page.sync="currentPage" @current-change="handlePage" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      stations: [],
      station: null,
      taskCalendar: new Date(),
      startTime: null,
      endTime: null,
      taskStateList: null,
      checkedType: [],
      patrolTypes: [],
      checkedStatus: [],
      taskStatus: [],
      taskName: '',
      taskData: [],
      currentPage: null,
      pageSize: 10,
      total: null
    }
  },
  created() {
    const now = new Date()
    const year = now.getFullYear()
    const month = now.getMonth() + 1
    const day = now.getDate()
    this.startTime = new Date(year, month - 1, day - 7, 0, 0, 0)
    this.endTime = new Date(year, month - 1, day, 23, 59, 59)
    this.currentPage = 1
    this.total = 0
  },
  mounted() {
    this.getMasterList()
    this.getTaskStateList()
    this.getTaskTypeList()
    this.displayTaskList(this.currentPage)
    this.getDailyTaskGroup()
  },
  watch: {
    taskCalendar(newValue, oldValue) {
      if (this.getQueryTime(newValue) != this.getQueryTime(oldValue)) {
        this.getDailyTaskGroup()
      }
    }
  },
  methods: {
    changeStation() {
      this.currentPage = 1
      this.total = 0
      this.displayTaskList(this.currentPage)
      this.getDailyTaskGroup()
    },
    handlePage(currentPage) {
      this.displayTaskList(currentPage)
    },
    search() {
      this.currentPage = 1
      this.displayTaskList(this.currentPage)
    },
    reset() {
      this.startTime = null
      this.endTime = null
      this.taskName = ''
      this.checkedStatus = []
      this.checkedType = []
    },
    // handleQuery(row) {
    //   console.log('处理查看')
    // },
    getMasterList() {
      axios.post(`http://${this.$store.getters.serverUrl}/station/user/masterList`, null, {
        headers: {
          Gz_security_token: this.$store.getters.Gz_security_token
        }
      }).then(({ data }) => {
        if (data.success) {
          this.stations = data.data
          if (this.stations != null && this.stations.length > 0)
            this.station = this.stations[0].id
        }
      })
    },
    getTaskStateList() {
      axios.post(`http://${this.$store.getters.serverUrl}/station/webTaskDisplayController/getTaskStateList`, null, {
        params: {
          masterId: this.station
        },
        headers: {
          Gz_security_token: this.$store.getters.Gz_security_token
        }
      }).then(({ data }) => {
        if (data.success) {
          this.taskStatus = data.data
        }
      })
    },
    getTaskTypeList() {
      axios.post(`http://${this.$store.getters.serverUrl}/station/webTaskDisplayController/getTaskTypeList`, null, {
        params: {
          masterId: this.station
        },
        headers: {
          Gz_security_token: this.$store.getters.Gz_security_token
        }
      }).then(({ data }) => {
        if (data.success) {
          this.patrolTypes = data.data
        }
      })
    },
    displayTaskList(currentPage) {
      axios.post(`http://${this.$store.getters.serverUrl}/station/webTaskDisplayController/displayTaskList`,
        {
          curPage: currentPage,
          endTime: this.formattedTime(this.endTime),
          pageSize: this.pageSize,
          patrolType: this.checkedType.join(','),
          startTime: this.formattedTime(this.startTime),
          taskName: this.taskName,
          taskState: this.checkedStatus.join(',')
        },
        {
          params: {
            masterId: this.station
          },
          headers: {
            Gz_security_token: this.$store.getters.Gz_security_token
          }
        }).then(({ data }) => {
          if (data.success) {
            if (data.data != null) {
              this.taskData = data.data.webTaskRunVOList
              this.total = data.data.pageInfo.total
            }
          }
        })
    },
    getDailyTaskGroup() {
      axios.post(`http://${this.$store.getters.serverUrl}/station/webTaskDisplayController/getDailyTaskGroup`, null, {
        params: {
          queryDate: this.getQueryTime(this.taskCalendar),
          masterId: this.station
        },
        headers: {
          Gz_security_token: this.$store.getters.Gz_security_token
        }
      }).then(({ data }) => {
        if (data.success) {
          this.taskStateList = data.data
        }
      })
    },
    formattedTime(dateTime) {
      if (dateTime == null)
        return null
      const year = dateTime.getFullYear()
      const month = (dateTime.getMonth() + 1).toString().padStart(2, '0')
      const day = dateTime.getDate().toString().padStart(2, '0')
      const hour = dateTime.getHours().toString().padStart(2, '0')
      const minute = dateTime.getMinutes().toString().padStart(2, '0')
      const second = dateTime.getSeconds().toString().padStart(2, '0')
      return `${year}-${month}-${day} ${hour}:${minute}:${second}`
    },
    formattedDate(dateTime) {
      if (dateTime == null)
        return null
      const year = dateTime.getFullYear()
      const month = (dateTime.getMonth() + 1).toString().padStart(2, '0')
      const day = dateTime.getDate().toString().padStart(2, '0')
      return `${year}-${month}-${day}`
    },
    getQueryTime(dateTime) {
      if (dateTime == null)
        return null
      const year = dateTime.getFullYear()
      const month = (dateTime.getMonth() + 1).toString().padStart(2, '0')
      return `${year}-${month}`
    }
  }
}
</script>
<style scoped>
.body {
  margin-left: 20px;
  width: 1876px;
  height: 960px;
  background: rgba(1, 55, 66, 1);
  border: 1px solid rgba(0, 188, 191, 1);
  box-shadow: inset 20px 0px 35px -9px rgba(6, 115, 115, 1);
}

.body-top {
  height: 56px;
  background: rgba(80, 211, 225, 0.15);
  display: flex;
  align-items: center;
}

.body-top-title {
  margin-left: 20px;

  .el-input__prefix {
    display: flex;
    align-items: center;
    font-size: 22px;
    font-weight: 500;
    color: rgba(223, 238, 243, 1);
  }

  .el-input__inner {
    padding-bottom: 2px;
    padding-left: 70px;
    width: 180px;
    font-size: 22px;
    font-weight: 500;
    letter-spacing: 1px;
    background: none;
    border: none;
    color: rgba(223, 238, 243, 1);
  }

  .el-select-dropdown {
    background: rgba(7, 131, 140, 1);
    border: 1px solid rgba(7, 131, 140, 1);
  }

  .el-select-dropdown__item {
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 1px;
    background: rgba(7, 131, 140, 1);
    color: rgba(223, 238, 243, 1);
  }

  .el-select-dropdown__item:hover {
    background: rgba(17, 173, 240, 0.1);
    border: 1px solid rgba(17, 173, 240, 0.2);
    box-shadow: inset 0px 0px 9.34px rgba(0, 153, 255, 0.5);
    font-size: 20px;
  }

  .el-select-dropdown__item.selected {
    color: #409EFF;
  }
}

.body-content-top {
  display: flex;
  align-items: center;
  font-size: 20px;
  font-weight: 700;
  color: rgba(0, 255, 255, 1);
}

.body-content-top-left {
  display: flex;
  align-items: center;
  height: 60px;
  width: 820px;
  margin: 20px 20px 10px 18px;
  padding-left: 51px;
  background: linear-gradient(90deg, rgba(0, 255, 255, 0.4) 0%, rgba(13, 128, 236, 0) 100%);
  letter-spacing: 4px;
}

.body-content-top-right {
  display: flex;
  align-items: center;
  height: 60px;
  width: 1000px;
  margin-top: 20px;
  margin-bottom: 10px;
  padding-left: 51px;
  background: linear-gradient(90deg, rgba(0, 255, 255, 0.4) 0%, rgba(13, 128, 236, 0) 100%);
  letter-spacing: 4px;
}

.body-content-bottom {
  display: flex;
  width: 1840px;
  height: 796px;
  margin-left: 18px;
}

.body-content-bottom-left {
  width: 820px;
  height: 796px;
  border-radius: 4px;
  background: rgba(13, 79, 90, 1);

  .el-calendar {
    background: rgba(13, 79, 90, 1);
  }

  .el-calendar__title {
    font-size: 23px;
    font-weight: 500;
    color: rgba(255, 255, 255, 1);
  }

  .el-button-group .el-button {
    background: rgba(80, 211, 225, 0.5);
    font-size: 14px;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
    border: none;
    margin-left: 7px;
  }

  .el-calendar__header {
    border-bottom: none;
    padding: 12px 20px 0 20px;
  }

  .el-calendar__body {
    padding: 12px 20px;
  }

  .el-calendar-table {
    border-radius: 7px 7px, 0px, 0px;
    background: rgba(80, 211, 225, 0.15);
  }

  .el-calendar-table th {
    font-size: 14px;
    font-weight: 400;
    color: rgba(229, 229, 229, 1);
    border: 1px solid rgba(30, 119, 135, 1);
  }

  .el-calendar-table td {
    font-size: 12px;
    font-weight: 500;
    color: rgba(255, 255, 255, 1);
    border: 1px solid rgba(30, 119, 135, 1);
  }

  .el-calendar-day {
    height: 108px;
    padding: 0;
    color: rgba(166, 166, 166, 1);
  }

  .el-calendar-table .el-calendar-day:hover {
    background-color: rgba(7, 131, 140, 1);
    color: rgba(255, 255, 255, 1);
  }

  .el-calendar-table td.is-selected {
    background-color: rgba(7, 131, 140, 1);
  }

  .text-default {
    width: 14px;
    height: 14px;
    margin: 2px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 1);
  }

  .text-selected {
    width: 14px;
    height: 14px;
    margin: 2px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 1);
    background-color: rgba(0, 186, 173, 1);
  }

  .task-status {
    margin-left: 4px;
    margin-bottom: 3px;
    width: 90px;
    font-size: 11px;
    font-weight: 400;
  }

  .task-status-selected {
    margin-left: 4px;
    margin-bottom: 3px;
    width: 90px;
    font-size: 11px;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
  }

  .task-count {
    float: right;
  }
}

.body-content-bottom-right {
  width: 1000px;
  height: 796px;
  margin-left: 20px;
  background: rgba(1, 55, 66, 1);

  .body-content-bottom-right-search {
    background: rgba(13, 79, 90, 1);
    padding: 16px 0 0 12px;
    height: 206px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(223, 238, 243, 1);

    .search-input {
      display: flex;
      height: 36px;

      .custom-input {
        margin-right: 15px;
        font-size: 14px;
        font-weight: 500;
        color: rgba(229, 229, 229, 1);
      }

      .el-input__prefix {
        display: none;
      }

      .el-input-group__prepend {
        width: 72px;
        padding: 0;
        border: none;
        font-size: 14px;
        font-weight: 500;
        background: rgba(13, 79, 90, 1);
        color: rgba(255, 255, 255, 1);
      }

      .el-input__inner {
        font-size: 14px;
        font-weight: 500;
        color: rgba(229, 229, 229, 1);
        padding-left: 10px;
        border: none;
        background: rgba(209, 209, 209, 0.15);
        box-shadow: inset 0px 0px 4px rgba(80, 211, 225, 0.25);
      }
    }

    .search-checkbox {
      display: flex;
      margin: 18px 0 0 0;

      .el-checkbox-group {
        width: 900px;
      }

      .el-checkbox {
        width: 145px;
        font-size: 14px;
        font-weight: 500;
        color: rgba(229, 229, 229, 1);
        margin-left: 5px;
        margin-right: 0;
      }

      .el-checkbox__inner {
        border-radius: 50%;
        background: rgba(13, 79, 90, 1);
        border: 1px solid rgba(229, 230, 235, 1);
      }

      .el-checkbox .el-checkbox__input.is-checked .el-checkbox__inner {
        background: rgba(0, 125, 125, 1);
        border: 1px solid rgba(0, 125, 125, 1);
      }

      .el-checkbox__label {
        font-size: 14px;
        font-weight: 500;
        color: rgba(229, 229, 229, 1);
      }
    }

    .search-btn {
      flex: 1;
      text-align: right;
      margin-top: 10px;
      margin-right: 15px;

      .el-button {
        width: 80px;
        height: 36px;
        border: none;
        border-radius: 2px;
        background: rgba(80, 211, 225, 0.5);
        box-shadow: inset 0px 0px 4px rgba(80, 211, 225, 0.25);
        font-size: 16px;
        font-weight: 500;
        color: rgba(255, 255, 255, 1);
      }
    }
  }

  .body-content-bottom-right-taskListTitle {
    display: flex;
    align-items: center;
    height: 60px;
    /* border-bottom: 2px solid rgba(85, 92, 102, 1); */
    background: linear-gradient(90deg, rgba(0, 255, 255, 0.4) 0%, rgba(13, 128, 236, 0) 100%);
    font-size: 20px;
    font-weight: 700;
    color: rgba(0, 255, 255, 1);
    padding-left: 51px;
    margin-top: 20px;
    letter-spacing: 4px;
  }

  .body-content-bottom-right-table {
    display: flex;
    width: 1000px;
    border-radius: 4px;
    background: rgba(13, 79, 90, 1);

    .body-content-bottom-right-taskList {
      background: rgba(13, 79, 90, 1);
      margin-top: 10px;
      width: 1000px;
      height: 427px;

      .taskList-table {
        margin-left: 15px;

        .el-table {
          background: rgba(13, 79, 90, 1);
        }

        .el-table .el-table__row {
          height: 40px;
        }

        .el-table th {
          font-size: 14px;
          font-weight: 500;
          color: rgba(229, 229, 229, 1);
          background: rgba(13, 79, 90, 1);
          border: none;
          text-align: center;
        }

        .el-table td {
          text-align: center;
          font-size: 14px;
          font-weight: 500;
          color: rgba(229, 229, 229, 1);
          background: rgba(13, 79, 90, 1);
          border: none;
        }

        .el-table::before {
          background: none;
        }

        .end-column::before {
          background: none;
        }

        .el-button {
          font-size: 14px;
          font-weight: 500;
          color: rgba(229, 229, 229, 1);
        }

        .el-button:hover {
          cursor: pointer;
        }

        .el-table__fixed::before,
        .el-table__fixed-right::before {
          background: none;
        }

        .el-table__body tr:hover>td {
          background: rgba(52, 59, 69, 1);

        }

        .el-table--medium th,
        .el-table--medium td {
          padding: 2px 0;
        }
      }
    }
  }

  .body-content-bottom-right-page {
    height: 74px;
    display: flex;
    justify-content: center;
    padding-top: 15px;
    background: rgba(13, 79, 90, 1);
    border: 1px solid;
    border-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(135, 135, 135, 0.5), rgba(255, 255, 255, 0)) 1 10;

    .el-pagination__total {
      width: 60px;
      height: 28px;
      background: rgba(13, 79, 90, 1);
      color: rgba(193, 206, 222, 1);
      font-size: 12px;
      font-weight: 400;
      border: 1px solid rgba(177, 200, 230, 0.2);
      text-align: center;
    }

    .el-pagination .btn-prev {
      width: 24px;
      height: 28px;
      background: rgba(13, 79, 90, 1);
      color: rgba(193, 206, 222, 1);
      font-size: 12px;
      font-weight: 400;
      border: 1px solid rgba(177, 200, 230, 0.2);
    }

    .el-pagination .btn-prev:hover {
      background: rgba(30, 119, 135, 1);
      color: rgba(255, 255, 255, 1);
    }

    .el-pagination .btn-quickprev {
      width: 24px;
      height: 28px;
      background: rgba(13, 79, 90, 1);
      color: rgba(193, 206, 222, 1);
      font-size: 12px;
      font-weight: 400;
      border: 1px solid rgba(177, 200, 230, 0.2);
    }

    .el-pagination .btn-quickprev:hover {
      background: rgba(30, 119, 135, 1);
      color: rgba(255, 255, 255, 1);
    }

    .el-pagination .btn-next {
      width: 24px;
      height: 28px;
      background: rgba(13, 79, 90, 1);
      color: rgba(193, 206, 222, 1);
      font-size: 12px;
      font-weight: 400;
      border: 1px solid rgba(177, 200, 230, 0.2);
    }


    .el-pagination .btn-next:hover {
      background: rgba(30, 119, 135, 1);
      color: rgba(255, 255, 255, 1);
    }

    .el-pagination .btn-quicknext {
      width: 24px;
      height: 28px;
      background: rgba(13, 79, 90, 1);
      color: rgba(193, 206, 222, 1);
      font-size: 12px;
      font-weight: 400;
      border: 1px solid rgba(177, 200, 230, 0.2);
    }

    .el-pagination .btn-quicknext:hover {
      background: rgba(30, 119, 135, 1);
      color: rgba(255, 255, 255, 1);
    }


    .el-pagination .number {
      width: 24px;
      height: 28px;
      background: rgba(13, 79, 90, 1);
      color: rgba(193, 206, 222, 1);
      font-size: 12px;
      font-weight: 400;
      border: 1px solid rgba(177, 200, 230, 0.2);
    }

    .el-pagination .number:hover {
      background: rgba(30, 119, 135, 1);
      color: rgba(255, 255, 255, 1);
    }

    .el-pagination .number.active {
      background: rgba(30, 119, 135, 1);
      color: rgba(255, 255, 255, 1);
    }

    .el-pagination .el-icon-more {
      width: 24px;
      height: 28px;
      background: rgba(13, 79, 90, 1);
      color: rgba(193, 206, 222, 1);
      font-size: 12px;
      font-weight: 400;
      border: 1px solid rgba(177, 200, 230, 0.2);
    }

    .el-pagination .el-icon-more:hover {
      background: rgba(30, 119, 135, 1);
      color: rgba(255, 255, 255, 1);
    }
  }

}
</style>
